/**
 * Created by levy on 16/6/15.
 //show it when no data: rush/sign_for/task_processing
 */

/**
 * span_text 提示文字字段
 * btn_text 不传则无按钮
 * page_url 按钮去到的页面, 无按钮则不传
 * page_title 页面名字, 无按钮则不传
 */
var NoData = React.createClass({
    clickFn: function () {
        var data = this.props.data;
        liefeng.bridgeJs.doLocation(data.page_url,data.page_title);
    },
    componentDidMount() {
        // 禁用上拉刷新
        let $pullrefresh = mui('#pullrefresh').pullRefresh();
        try {
            $pullrefresh && $pullrefresh.disablePullupToRefresh();
        }catch (e) {
            console.warn('应该是当前PullRefresh组件没有指定pullupFn.不过不影响页面渲染 ' + e);
        }
    },
    componentWillUnmount() {
        // 重新启用
        let $pullrefresh = mui('#pullrefresh').pullRefresh();
        $pullrefresh && $pullrefresh.enablePullupToRefresh();
    },
    render: function () {
        var data = this.props.data || {};
        return(
            <div className="no-data flex-box-col">
                <img src="../public/images/common/no_data.png" alt="暂无记录"/>
                <span>{data.span_text || '暂无数据'}</span>
                {
                    data.btn_text ?
                        <button onTouchEnd={this.clickFn} className="mui-btn">
                            {data.btn_text}
                        </button> :
                       ''
                }
            </div>
        );
    }
});
export default NoData;
